//
//  VideoCollectionViewCell.m
//  WWXELuShang
//
//  Created by lanou on 15/12/21.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "VideoCollectionViewCell.h"
#import "VideoModel.h"

@implementation VideoCollectionViewCell



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kBackGroundColor;
        [self.contentView addSubview:self.iconView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.playNumberLabel];
        [self.contentView addSubview:self.timeLabel];
       
        [self addImageView];
    }
    
    return self;
}


- (void)addImageView {
    
    
    NSArray *array = @[@"videoPlay", @"time"];
    for (int i = 0; i < 2; i ++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * self.frame.size.width / 2, kWidth / 40 * 3 + self.iconView.frame.size.height + 30, kWidth / 20, kWidth / 20)];
        imageView.image = [UIImage imageNamed:array[i]];
        [self.contentView addSubview:imageView];
    }

    
}


- (UIImageView *)iconView {
    if (!_iconView) {
        _iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, kWidth / 40, self.frame.size.width, self.frame.size.width / 16 * 9)];
    }
    
    return _iconView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.iconView.frame.size.height + kWidth / 20, self.frame.size.width, 30)];
        _titleLabel.font = [UIFont boldSystemFontOfSize:12];
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

- (UILabel *)playNumberLabel {
    if (!_playNumberLabel) {
        _playNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth / 40 * 3, kWidth / 40 * 3 + self.iconView.frame.size.height + 30, self.frame.size.width / 3, kWidth / 20)];
        _playNumberLabel.font = [UIFont systemFontOfSize:kWidth / 30];
        _playNumberLabel.textColor = [UIColor grayColor];
    }
    return _playNumberLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 + kWidth / 40 * 3, kWidth / 40 * 3 + self.iconView.frame.size.height + 30, self.frame.size.width / 4, kWidth / 20)];
        _timeLabel.font = [UIFont systemFontOfSize:kWidth / 30];
        _timeLabel.textColor = [UIColor grayColor];
        
    }
    return _timeLabel;
}



- (void)setVideoModel:(VideoModel *)videoModel {
    if (_videoModel != videoModel) {
        _videoModel = videoModel;
        NSString *imageUrl = [videoModel.ImageLink stringByReplacingOccurrencesOfString:@"-{0}-{1}" withString:@"-320-150"];
        self.iconView.image = [UIImage imageNamed:@"loadCar.jpeg"];
        
        [self.iconView setImageWithURL:[NSURL URLWithString:imageUrl]];
        self.titleLabel.text = videoModel.Title;
        
        CGFloat number = videoModel.TotalVisit / 10000;
        if (number > 1) {
            self.playNumberLabel.text = [NSString stringWithFormat:@"%.1f万",number];
        }else {
            self.playNumberLabel.text = [NSString stringWithFormat:@"%ld",videoModel.TotalVisit];
        }
        self.timeLabel.text = videoModel.Duration;
    }
    
}


@end
